package com.konke.sdslibrary.util;

import com.sds.sdk.android.sh.model.SHResult;

import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;

/**
 * Created by L on 2016/6/30.
 */
public final class AsynTool {


    public static void sync(Future future) {
        final Object lock = new Object();

        future.addListener(new GenericFutureListener<Future<? super SHResult>>() {
            @Override
            public void operationComplete(Future<? super SHResult> future) throws Exception {
                synchronized (lock) {
                    lock.notifyAll();
                }
            }
        });
        try {
            if (!future.isDone()) {
                synchronized (lock) {
                    lock.wait(90 * 1000);
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
